package com.kilomob.grady.client.netty;

import io.netty.channel.Channel;
import io.netty.channel.ChannelFactory;
import io.netty.channel.socket.nio.NioSocketChannel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class NettyChannelFactory implements ChannelFactory<NioSocketChannel> {
//    private static Logger LOGGER = LoggerFactory.getLogger(NettyChannelFactory.class);
    private static final Map<String,List<Channel>> CHANNEL_MAPS = new HashMap<String, List<Channel>>();
    private volatile List<Channel> channels;
    private String clientId;
    
    public NettyChannelFactory(String clientId){
        this.clientId = clientId;
    }
    
    
    @Override
    public NioSocketChannel newChannel() {
        NioSocketChannel channel = new NioSocketChannel();
        CHANNEL_MAPS.get(clientId);
        channels.add(channel);
        return channel;
    }
    
    
    public void setConnections(int i){
        channels = new ArrayList<Channel>();
        CHANNEL_MAPS.put(clientId, channels);
    }
    
    public static List<Channel> getChannels(String clientId){
        return CHANNEL_MAPS.get(clientId);
    }

}
